package com.fantasy.demo1.component;

import com.fantasy.demo1.entity.SecurityUser;
import com.fantasy.demo1.service.SecurityUserService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("userDetailsService")
public class CustomUserDetailsService implements UserDetailsService {

    @Autowired
    private SecurityUserService securityUserService;

    private GrantedAuthority DEFAULT_ROLE = new SimpleGrantedAuthority("USER");

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        UserDetails user = null;
        try {
            user = (UserDetails) securityUserService.getUser(s);
            System.out.println(user);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return user;
    }
}
